package mainpackage;

/**
 *
 * @author Eric Kisner
 */
public class MainViewHandler {

    private MainClientView view;

    public MainViewHandler( MainClientView view ) {
        this.view = view;
    }

    /**
     * Resets any fields of the specified tab.
     * @param c The first letter of the tab to reset its fields. 'p' is the Player tab, 't' is the Team tab,
     * 'g' is the Game tab.
     */
    public void resetFields( char c ) {
        switch( c ) {
            //Reset "Player" tab fields
            case 'p':
                view.playerNameField.setText( "" );
                view.teamNameField.setText( "" );
                view.heightField.setText( "" );
                view.goalsScoredField.setText( "" );
                view.hometownField.setText( "" );
                view.playerTableHolder.removeAll();
                view.deletePlayerButton.setEnabled( false );
                view.updatePlayerButton.setEnabled( false );
                break;

            //Reset "Team" tab fields
            case 't':
                view.teamNameField2.setText( "" );
                view.divisionNameField.setText( "" );
                view.conferenceNameField.setText( "" );
                view.homeArenaNameField.setText( "" );
                view.teamGoalsScoredField.setText( "" );
                view.teamGoalsScoredAgainstField.setText( "" );
                view.overtimeWinsField.setText( "" );
                view.pointsField.setText( "" );
                view.totalLossesField.setText( "" );
                view.totalWinsField.setText( "" );
                view.teamTableHolder.removeAll();
                view.deleteTeamButton.setEnabled( false );
                view.updateTeamButton.setEnabled( false );
                break;

            //Reset "Game" tab fields
            case 'g':
                view.awayTeamNameField.setText( "" );
                view.homeTeamNameField.setText( "" );
                view.hostArenaNameField.setText( "" );
                view.gameDatePlayedField.setText( "" );
                view.winnerTeamNameField.setText( "" );
                view.loserTeamNameField.setText( "" );
                view.winnerScoreField.setText( "" );
                view.loserScoreField.setText( "" );
                view.gameTableHolder.removeAll();
                view.deleteGameButton.setEnabled( false );
                view.updateGameButton.setEnabled( false );
                break;

            //If we get an invalid char, just reset all fields.
            default:
                resetFields( 'p' );
                resetFields( 't' );
                resetFields( 'g' );
                break;
        }
    }

    /**
     * Resets the entire view.
     * @param c
     */
    public void resetAll( char c ) {
        switch( c ) {
            //Reset "Player" tab
            case 'p':
                view.playerTableHolder.removeAll();
                view.deletePlayerButton.setEnabled( false );
                view.updatePlayerButton.setEnabled( false );
                break;

            //Reset "Team" tab
            case 't':
                view.teamTableHolder.removeAll();
                view.deleteTeamButton.setEnabled( false );
                view.updateTeamButton.setEnabled( false );
                break;

            //Reset "Game" tab
            case 'g':
                view.gameTableHolder.removeAll();
                view.deleteGameButton.setEnabled( false );
                view.updateGameButton.setEnabled( false );
                break;

            //If we get an invalid char, just reset all fields.
            default:
                resetAll( 'p' );
                resetAll( 't' );
                resetAll( 'g' );
                break;
        }
        resetFields( c );
    }
}
